using System;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.Xml;

namespace MsBuildAxTasks.Tasks
{
    public class AxImport : Task
    {
        private string _xpoFile;

        [Required]
        public string XpoFile
        {
            get { return _xpoFile; }
            set { _xpoFile = value; }            
        }

        public override bool Execute()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
                doc.AppendChild(docNode);

                XmlNode AxaptaAutoRun = doc.CreateElement("AxaptaAutoRun");
                doc.AppendChild(AxaptaAutoRun);

                XmlNode xpoImport = doc.CreateElement("XpoImport");
                XmlAttribute productAttribute = doc.CreateAttribute("file");
                productAttribute.Value = _xpoFile;
                xpoImport.Attributes.Append(productAttribute);
                AxaptaAutoRun.AppendChild(xpoImport);

                //doc.Save(Console.Out);

                //this.open();
            }
            catch (Exception ex)
            {
                Log.LogErrorFromException(ex);
                return false;
            }

            //Log.LogMessage(Properties.Resources.XmlReadResult, _value);

            return true;
        }
    }
}
